// pages/view/drug/drlMedicines/drlMedicines.js
const network = require('../../../../utils/network.js')
var startTime_n;
var endTime_n;
var dept_n=1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    chartType: 1,

    changeFlag_cl: true,
    changeFlag_ip: false,
    //背景颜色
    clBg: '#37a2da',
    ipBg: '#C1C1C1',
    
    headers: [{ text: 'doctorName', display: '' }, { text: 'antibacterialFee', display: '' }, { text: 'antibacterialFeeInTotal', display: '' }, { text: 'genericFee', display: '' }, { text: 'genericFeeInTotal', display: '' }, { text: 'total', display: '' }],
    row: [],
    
    deptName:"",
    antibacterialFee: "",
    antibacterialFeeInTotal: "",
    genericFee: "",
    genericFeeInTotal: "",
    total: "",
  },
  onChange(e) {
    console.log('onChange', e)
    this.setData({
      current: e.detail.current,
    })

    this.myRequest(e)
  },
  myRequest: function (options) {
    var that = this
    console.log('options:', options)
    //调用封装好的网络请求，获取数据//options.startTime + '&endTime=' + options.endTime
    network.get('/drug/medicines?startTime=' + '2018-03-01' + '&endTime=' + '2020-03-12' + '&dept=' + dept_n, {})
      .then(function (res) {
        console.log('res:', res)
        var obj1 = res.data.data

        that.setData({
          startTime: startTime_n,
          endTime: endTime_n,
          row: res.data.data,
         
          antibacterialFee: res.data.data_2.antibacterialFee,
          antibacterialFeeInTotal: res.data.data_2.antibacterialFeeInTotal,
          genericFee: res.data.data_2.genericFee,
          genericFeeInTotal: res.data.data_2.genericFeeInTotal,
          total: res.data.data_2.total,
        })
        console.log('row:', that.data.row)

      }).then(function (res) {
        wx.hideLoading()
      }).catch(function (res) {
        console.log(res)
      })
  },
  /**
    * 生命周期函数--监听页面加载
    */
  onLoad: function (options) {
    var that =this
    wx.showLoading({
      title: '加载中',
    })
    startTime_n = options.startTime
    endTime_n = options.endTime
    that.myRequest(options)
  },

  changeToCl: function (e) {
    var that = this;
    var flag = that.data.changeFlag_cl;
    console.log('flag:', flag)
    if (!flag) {
      that.data.changeFlag_cl = true
      that.setData({
        'changeFlag_cl': true,
        'changeFlag_ip': false,
        'clBg': "#37a2da",
        'ipBg': "#C1C1C1",
        chartType: 1
      })
      dept_n = 1;
      this.myRequest(e)
    }


  },
  changeToIp: function (e) {
    var that = this;
    var flag = that.data.changeFlag_ip;
    if (!flag) {
      that.setData({
        'changeFlag_cl': false,
        'changeFlag_ip': true,
        'clBg': "#C1C1C1",
        'ipBg': "#32c5e9",
        chartType: 2
       
      })
      dept_n=2;
      this.myRequest(e)
      

    }


  },
})